<html>
<#include "../common/header.ftl" />

<!--引入jquery和wangEditor.js-->
<!--注意：javascript必须放在body最后，否则可能会出现问题-->
<link rel="stylesheet" type="text/css"
	href="static/dist/css/wangEditor.min.css">
<link rel="stylesheet" type="text/css" href="static/css/select.css">
<script type="text/javascript" src="static/dist/js/wangEditor.min.js"></script>
<script type="text/javascript" src="static/js/select.js"></script>
</head>
<script type="text/javascript">
	$(function() {
		$('#subBtn').on('click', function() {
			if (($("#ip1").val().trim()) == '') {
				tip('标题不可为空');
				return;
			}
			if (($("#textarea1").val().trim()) == '') {
				tip('内容不可为空！');
				return;
			}
			let obj = {};
			obj.newsName = $("#ip1").val().trim();
			obj.newsAuthor = $("#ip2").val().trim();
			obj.uId = parseInt($("#ip3").val().trim());
			obj.newsContent = $("#textarea1").val().trim();
			obj.newsType = $("#ip4").val();
			obj.newsKeywords = $("#ip5").val().trim();
			console.log(JSON.parse(JSON.stringify(obj)))
			$.ajax({
				url : "news?method=add",
				type : "POST",
				data : JSON.stringify(obj),
				scriptCharset : 'utf-8',
				contentType : "application/json; charset=utf-8",
				success : function(res) {
					console.log(JSON.parse(res))
					let data = JSON.parse(res)
					if (data.code === 0) {
						tip(data.msg)
						setTimeout("location.href='news?method=list'", 1000)
					} else {
						tip(data.msg)
					}
				},
				error : function(res) {
					console.log("res", res);
				}
			});
			/* console.log('data', $('form').serializeArray()) */
		})
	});
	function tip(msg) {
		$("#warn").text(msg)
		$("#modal-282051").click()
	}
</script>
<#if Session.user ?? && user.role==1>
<body style="margin-left: 200px">

	<div id="wrapper" class="toggled"><#--边栏sidebar--> <#include
		"../common/nav.ftl" /> <#--主要内容content--></div>
	<#else>
<body>

	</#if>
	<div class="container">

		<div class="row clearfix">

			<div class="col-md-12 column">

				<#include "../common/bread.ftl"/> <#include "../modal/tips.ftl"/> <a
					id="modal-282051" href="#modal-warns" style="display: none"
					role="button" class="" data-toggle="modal"></a>
				<form class="container"
					style="width: 80%; margin: 0 auto; max-width: 1380px" role="form">
					<div class="form-group">
						<label>新闻名称</label> <input id="ip1" class="form-control"
							placeholder="请输入..." type="text" name="newsName" />
					</div>
					<div class="form-group">
						<div style="width: 50%">
							<label>新闻作者</label> <input id="ip2" class="form-control"
								placeholder="请输入..." type="text" name="newsAuthor" />
						</div>
						<div style="width: 50%">
							<label>新闻类型</label> <select id="ip4" name="newsType"
								multiple="multiple" class="form-control"
								style="border: 1px solid #555; padding: 0.5em; font-size: 15px; line-height: 1.2em; background: #fff; -webkit-appearance: none; -webkit-box-shadow: 2px 1px 1px #fff; -webkit-border-radius: 0.5em;">
								<#if types ??> <#list types as item>
								<option value=${typesid[item_index]} >${item }</option> </#list>
								</#if>
							</select>
						</div>
						<div style="width: 50%">
							<label>关键字</label> <input id="ip5" class="form-control"
								placeholder="请输入..." type="text" name="newsKeywords" />
						</div>
					</div>
					<div class="form-group">
						<label>新闻内容</label>
						<textarea name="newsContent" id="textarea1" style="height: 300px"
							placeholder="请输入...">
						</textarea>
						<script type="text/javascript">
							var editor = new wangEditor('textarea1');
							editor.create();
						</script>

					</div>
					<input id="ip3" type="hidden"
						value='<#if Session.user ??> ${Session.user.id } </#if>' />
					<button id="subBtn" type="button" class="btn btn-default">
						提交
					</button>
				</form>
			</div>
			<script src="static/js/3.1.0bootstrap.min.js"></script>
</body>
</html>

